package com.jswl.training.springjpa.dao;

import com.jswl.training.springjpa.entity.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface UserRepository extends JpaRepository<User,Long> ,JpaSpecificationExecutor<User> {

    /**
     * 基于方法名称命名规则查询
     * @param userName
     * @return
     */
    public List<User> findByUserName(String userName);

    public List<User> findByUserNameAndPhone(String userName,String phone);

    public List<User> findByUserNameOrPhone(String userName,String phone);

    /**
     * 基于注解 sql
     * @param userName
     * @return
     */
    @Query(value = "select * from tb_user where user_name like concat('%' ,?1,'%') order by create_time desc" , nativeQuery = true)
    public List<User> getUsersBy(@Param("userName") String userName);



}
